\doxysection{C\+:/\+Users/\+ASUS/\+Desktop/dm-\/ctrl\+H7-\/balance-\/9025test/modules/motor/\+DJImotor/dji\+\_\+motor.h File Reference}
\hypertarget{dji__motor_8h}{}\label{dji__motor_8h}\index{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/modules/motor/DJImotor/dji\_motor.h@{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/modules/motor/DJImotor/dji\_motor.h}}


DJI智能电机头文件  


{\ttfamily \#include "{}bsp\+\_\+can.\+h"{}}\newline
{\ttfamily \#include "{}controller.\+h"{}}\newline
{\ttfamily \#include "{}motor\+\_\+def.\+h"{}}\newline
{\ttfamily \#include "{}stdint.\+h"{}}\newline
{\ttfamily \#include "{}daemon.\+h"{}}\newline
\doxysubsubsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \mbox{\hyperlink{struct_d_j_i___motor___measure__s}{DJI\+\_\+\+Motor\+\_\+\+Measure\+\_\+s}}
\item 
struct \mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}}
\begin{DoxyCompactList}\small\item\em DJI intelligent motor typedef. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\Hypertarget{dji__motor_8h_ab915b1993f2ebada9197d1c91cd93975}\label{dji__motor_8h_ab915b1993f2ebada9197d1c91cd93975} 
\#define {\bfseries DJI\+\_\+\+MOTOR\+\_\+\+CNT}~12
\item 
\Hypertarget{dji__motor_8h_a90084360b2511ca782b9678afc9bc12d}\label{dji__motor_8h_a90084360b2511ca782b9678afc9bc12d} 
\#define {\bfseries SPEED\+\_\+\+SMOOTH\+\_\+\+COEF}~0.\+85f
\item 
\Hypertarget{dji__motor_8h_a33cdc99b8eade9b0152839f6066effa6}\label{dji__motor_8h_a33cdc99b8eade9b0152839f6066effa6} 
\#define {\bfseries CURRENT\+\_\+\+SMOOTH\+\_\+\+COEF}~0.\+9f
\item 
\Hypertarget{dji__motor_8h_a229ef24e35ce08a9a817f66d67f7b155}\label{dji__motor_8h_a229ef24e35ce08a9a817f66d67f7b155} 
\#define {\bfseries ECD\+\_\+\+ANGLE\+\_\+\+COEF\+\_\+\+DJI}~0.\+043945f
\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*} \mbox{\hyperlink{dji__motor_8h_ae6a2dbd0d46fc7d80c6e2339aad09969}{DJIMotor\+Init}} (\mbox{\hyperlink{struct_motor___init___config__s}{Motor\+\_\+\+Init\+\_\+\+Config\+\_\+s}} \texorpdfstring{$\ast$}{*}config)
\begin{DoxyCompactList}\small\item\em 调用此函数注册一个\+DJI智能电机,需要传递较多的初始化参数,请在application初始化的时候调用此函数 推荐传参时像标准库一样构造init\+Structure然后传入此函数. recommend\+: type xxxinit\+Structure = \{.member1=xx, .member2=xx, ....\}; 请注意不要在一条总线上挂载过多的电机(超过6个),若一定要这么做,请降低每个电机的反馈频率(设为500\+Hz), 并减小\+DJIMotor\+Control()任务的运行频率. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{dji__motor_8h_afc682af85b4e84a7a74d01097cf738e5}{DJIMotor\+Set\+Ref}} (\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}motor, float ref)
\begin{DoxyCompactList}\small\item\em 被application层的应用调用,给电机设定参考值. 对于应用,可以将电机视为传递函数为1的设备,不需要关心底层的闭环 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{dji__motor_8h_af949d3574538d826035110bf7e05c2f8}{DJIMotor\+Change\+Feed}} (\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}motor, \mbox{\hyperlink{motor__def_8h_a306d656c63a2d986e7aff57a0526395d}{Closeloop\+\_\+\+Type\+\_\+e}} loop, Feedback\+\_\+\+Source\+\_\+e type)
\begin{DoxyCompactList}\small\item\em 切换反馈的目标来源,如将角速度和角度的来源换为\+IMU(小陀螺模式常用) \end{DoxyCompactList}\item 
\Hypertarget{dji__motor_8h_a550e8d4dd6e722e66552563550191c65}\label{dji__motor_8h_a550e8d4dd6e722e66552563550191c65} 
void {\bfseries DJIMotor\+Control} ()
\begin{DoxyCompactList}\small\item\em 该函数被motor\+\_\+task调用运行在rtos上,motor\+\_\+stask内通过os\+Delay()确定控制频率 \end{DoxyCompactList}\item 
\Hypertarget{dji__motor_8h_a51d98dd3aee5e6e9530db1eb31f43642}\label{dji__motor_8h_a51d98dd3aee5e6e9530db1eb31f43642} 
void {\bfseries DJIMotor\+Stop} (\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}motor)
\begin{DoxyCompactList}\small\item\em 停止电机,注意不是将设定值设为零,而是直接给电机发送的电流值置零 \end{DoxyCompactList}\item 
\Hypertarget{dji__motor_8h_a7488031c4d093a41e2eaf8dd3881365b}\label{dji__motor_8h_a7488031c4d093a41e2eaf8dd3881365b} 
void {\bfseries DJIMotor\+Enable} (\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}motor)
\begin{DoxyCompactList}\small\item\em 启动电机,此时电机会响应设定值 初始化时不需要此函数,因为stop\+\_\+flag的默认值为0 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{dji__motor_8h_adbffe8a35fe1da0ed6c36227ce30f1cd}{DJIMotor\+Outer\+Loop}} (\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}motor, \mbox{\hyperlink{motor__def_8h_a306d656c63a2d986e7aff57a0526395d}{Closeloop\+\_\+\+Type\+\_\+e}} outer\+\_\+loop)
\begin{DoxyCompactList}\small\item\em 修改电机闭环目标(外层闭环) \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
DJI智能电机头文件 

\begin{DoxyAuthor}{Author}
neozng 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
0.\+2 
\end{DoxyVersion}
\begin{DoxyDate}{Date}
2022-\/11-\/01
\end{DoxyDate}
\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000010}{Todo}}]
\begin{DoxyEnumerate}
\item 给不同的电机设置不同的低通滤波器惯性系数而不是统一使用宏
\begin{DoxyEnumerate}
\item 为\+M2006和\+M3508增加开环的零位校准函数,并在初始化时调用(根据用户配置决定是否调用)
\end{DoxyEnumerate}
\end{DoxyEnumerate}\end{DoxyRefDesc}


\begin{DoxyCopyright}{Copyright}
Copyright (c) 2022 HNU Yue\+Lu EC all rights reserved
\end{DoxyCopyright}
\begin{DoxyAuthor}{Author}
neozng 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
0.\+2 
\end{DoxyVersion}
\begin{DoxyDate}{Date}
2022-\/11-\/01
\end{DoxyDate}
\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000012}{Todo}}]
\begin{DoxyEnumerate}
\item 给不同的电机设置不同的低通滤波器惯性系数而不是统一使用宏
\begin{DoxyEnumerate}
\item 为\+M2006和\+M3508增加开环的零位校准函数,并在初始化时调用(根据用户配置决定是否调用)
\end{DoxyEnumerate}
\end{DoxyEnumerate}\end{DoxyRefDesc}


\begin{DoxyCopyright}{Copyright}
Copyright (c) 2022 HNU Yue\+Lu EC all rights reserved 
\end{DoxyCopyright}


\label{doc-func-members}
\Hypertarget{dji__motor_8h_doc-func-members}
\doxysubsection{Function Documentation}
\Hypertarget{dji__motor_8h_af949d3574538d826035110bf7e05c2f8}\index{dji\_motor.h@{dji\_motor.h}!DJIMotorChangeFeed@{DJIMotorChangeFeed}}
\index{DJIMotorChangeFeed@{DJIMotorChangeFeed}!dji\_motor.h@{dji\_motor.h}}
\doxysubsubsection{\texorpdfstring{DJIMotorChangeFeed()}{DJIMotorChangeFeed()}}
{\footnotesize\ttfamily \label{dji__motor_8h_af949d3574538d826035110bf7e05c2f8} 
void DJIMotor\+Change\+Feed (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}}]{motor}{, }\item[{\mbox{\hyperlink{motor__def_8h_a306d656c63a2d986e7aff57a0526395d}{Closeloop\+\_\+\+Type\+\_\+e}}}]{loop}{, }\item[{Feedback\+\_\+\+Source\+\_\+e}]{type}{}\end{DoxyParamCaption})}



切换反馈的目标来源,如将角速度和角度的来源换为\+IMU(小陀螺模式常用) 


\begin{DoxyParams}{Parameters}
{\em motor} & 要切换反馈数据来源的电机 \\
\hline
{\em loop} & 要切换反馈数据来源的控制闭环 \\
\hline
{\em type} & 目标反馈模式 \\
\hline
\end{DoxyParams}
\Hypertarget{dji__motor_8h_ae6a2dbd0d46fc7d80c6e2339aad09969}\index{dji\_motor.h@{dji\_motor.h}!DJIMotorInit@{DJIMotorInit}}
\index{DJIMotorInit@{DJIMotorInit}!dji\_motor.h@{dji\_motor.h}}
\doxysubsubsection{\texorpdfstring{DJIMotorInit()}{DJIMotorInit()}}
{\footnotesize\ttfamily \label{dji__motor_8h_ae6a2dbd0d46fc7d80c6e2339aad09969} 
\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*} DJIMotor\+Init (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_motor___init___config__s}{Motor\+\_\+\+Init\+\_\+\+Config\+\_\+s}} \texorpdfstring{$\ast$}{*}}]{config}{}\end{DoxyParamCaption})}



调用此函数注册一个\+DJI智能电机,需要传递较多的初始化参数,请在application初始化的时候调用此函数 推荐传参时像标准库一样构造init\+Structure然后传入此函数. recommend\+: type xxxinit\+Structure = \{.member1=xx, .member2=xx, ....\}; 请注意不要在一条总线上挂载过多的电机(超过6个),若一定要这么做,请降低每个电机的反馈频率(设为500\+Hz), 并减小\+DJIMotor\+Control()任务的运行频率. 

\begin{DoxyAttention}{Attention}
M3508和\+M2006的反馈报文都是0x200+id,而\+GM6020的反馈是0x204+id,请注意前两者和后者的id不要冲突. 如果产生冲突,在初始化电机的时候会进入\+IDcrash\+\_\+\+Handler(),可以通过debug来判断是否出现冲突.
\end{DoxyAttention}

\begin{DoxyParams}{Parameters}
{\em config} & 电机初始化结构体,包含了电机控制设置,电机\+PID参数设置,电机类型以及电机挂载的\+CAN设置\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
DJIMotor\+Instance\texorpdfstring{$\ast$}{*} 
\end{DoxyReturn}
\Hypertarget{dji__motor_8h_adbffe8a35fe1da0ed6c36227ce30f1cd}\index{dji\_motor.h@{dji\_motor.h}!DJIMotorOuterLoop@{DJIMotorOuterLoop}}
\index{DJIMotorOuterLoop@{DJIMotorOuterLoop}!dji\_motor.h@{dji\_motor.h}}
\doxysubsubsection{\texorpdfstring{DJIMotorOuterLoop()}{DJIMotorOuterLoop()}}
{\footnotesize\ttfamily \label{dji__motor_8h_adbffe8a35fe1da0ed6c36227ce30f1cd} 
void DJIMotor\+Outer\+Loop (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}}]{motor}{, }\item[{\mbox{\hyperlink{motor__def_8h_a306d656c63a2d986e7aff57a0526395d}{Closeloop\+\_\+\+Type\+\_\+e}}}]{outer\+\_\+loop}{}\end{DoxyParamCaption})}



修改电机闭环目标(外层闭环) 


\begin{DoxyParams}{Parameters}
{\em motor} & 要修改的电机实例指针 \\
\hline
{\em outer\+\_\+loop} & 外层闭环类型 \\
\hline
\end{DoxyParams}
\Hypertarget{dji__motor_8h_afc682af85b4e84a7a74d01097cf738e5}\index{dji\_motor.h@{dji\_motor.h}!DJIMotorSetRef@{DJIMotorSetRef}}
\index{DJIMotorSetRef@{DJIMotorSetRef}!dji\_motor.h@{dji\_motor.h}}
\doxysubsubsection{\texorpdfstring{DJIMotorSetRef()}{DJIMotorSetRef()}}
{\footnotesize\ttfamily \label{dji__motor_8h_afc682af85b4e84a7a74d01097cf738e5} 
void DJIMotor\+Set\+Ref (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_d_j_i_motor_instance}{DJIMotor\+Instance}} \texorpdfstring{$\ast$}{*}}]{motor}{, }\item[{float}]{ref}{}\end{DoxyParamCaption})}



被application层的应用调用,给电机设定参考值. 对于应用,可以将电机视为传递函数为1的设备,不需要关心底层的闭环 


\begin{DoxyParams}{Parameters}
{\em motor} & 要设置的电机 \\
\hline
{\em ref} & 设定参考值 \\
\hline
\end{DoxyParams}
